import pandas as pd
import json

df = pd.read_excel('E22H-R CAN communication Matrix_MMI(AVM)-行程统计和超级续航-26个can信号.xlsx', sheet_name='Information_CAN_Message_Detail')
H_col = 'SignalName\n信号名称'  # 对应 'H' 的列索引
AA_col = 'ECP ID'  # 对应 'AA' 的列索引
AF_col = 'PRO_ID'  # 对应 'AA' 的列索引

print("Excel 文件的列名：", df.columns.tolist())

# 读取 signals.txt
with open('signals.txt', 'r') as file:
    signals = [line.strip() for line in file if line.strip()]

# 初始化结果字典
result = {}

# 遍历每个信号
for signal in signals:
    # 查找完全匹配的信号
    matched_rows = df[df[H_col].str.strip() == signal]

    # 如果找到匹配的行
    if not matched_rows.empty:
        # 取 U 列的值
        value_ecpID = matched_rows.iloc[0][AA_col]
        if pd.notna(value_ecpID):
            value_proID = matched_rows.iloc[0][AF_col]
            result[signal] = {"ecpId": value_ecpID, "proId": value_proID}

# 输出结果
print(result)

with open('result-epcID-3.json', 'w', encoding='utf-8') as json_file:
    json.dump(result, json_file, ensure_ascii=False, indent=4)
